# A “Watershed” Moment for Collaboration: 
# The Impacts of Legislation and Network Governance on Environmental Outcomes
# Yixin Liu, Jiho Kim, Tina Nabatchi 2025
# Public Administration Review
# Replication file for map creation

library(sf)
library(ggplot2)
library(egg)
library(cowplot)

####function####
element_textbox <- function(...) {
  el <- element_text(...)
  class(el) <- c("element_textbox", class(el))
  el
}

element_grob.element_textbox <- function(element, ...) {
  text_grob <- NextMethod()
  rect_grob <- element_grob(calc_element("strip.background", theme_bw()))
  
  ggplot2:::absoluteGrob(
    grid::gList(
      element_grob(calc_element("strip.background", theme_bw())),
      text_grob
    ),
    height = grid::grobHeight(text_grob), 
    width = grid::unit(1, "npc")
  )
}

####Data####
# Setup working directory
WD = getwd()
setwd(WD)
huc8 <- st_read("huc8_gis.shp")
owri <- st_read("owri_gis.shp")
owqi <- st_read("owqi_gis.shp")

####Figure 1####
# OWRI project map
project.map<-ggplot() + 
  geom_sf(data=owri,  color="green", size = 0.01) +
  geom_sf(data=huc8,  color="blue", fill=NA) +
  labs(title="Collaborative Projects\nin Oregon Watersheds (1997-2020)") +
  theme_bw() +
  theme(plot.title = element_textbox(
    hjust = 0.5, margin = margin(t = 5, b = 5)))
project.map

# OWQI map
owqi.map<-ggplot() + 
  geom_sf(data=owqi,  color="orange", size = 0.5) +
  geom_sf(data=huc8,  color="blue", fill=NA) +
  labs(title="Water Quality Monitoring Stations\nin Oregon Watersheds") +
  theme_bw() +
  theme(plot.title = element_textbox(
    hjust = 0.5, margin = margin(t = 5, b = 5)))
owqi.map

# combine
plot_figure1<-ggarrange(project.map,owqi.map,
                    ncol = 2, nrow = 1)

plot_figure1<-plot_grid(plot_figure1)
plot_figure1
ggsave(file = "figure1.jpg", width = 8, height = 4, dpi = 666)
ggsave(file = "figure1.eps", width = 8, height = 4, dpi = 666)


